<?php
namespace app\appletsapi\controller;

use app\common\model\Cart as CartModel;

class Cart extends Base
{
//    /**
//     * @route('applets/UserCartList')
//     * 用户购物车列表
//     */
    public function UserCartList()
    {
        $cartModel = new CartModel();
        $data = $cartModel->get_cart_list($this->GetUserInfo(),2,$this->_shopid);
//        var_dump($data);die;
        $this->result($data,1,'返回成功');
    }

//    /**
//     * @route('applets/UserEditCart')
//     * 用户编辑购物车(添加编辑)
//     */
    public function UserEditCart()
    {
        $cartModel = new CartModel();
        $productid = input('post.product_id');
        $quantity = input('post.quantity');
        $rs = $cartModel->editcart($this->_userid,$productid,$quantity,2);
        if(!$rs){
            $this->result('',-1,$cartModel->getError());
        }
        $this->result($rs,1,'编辑成功');
    }

//    /**
//     * @route('applets/UserDelCart')
//     * 删除购物车
//     */
    public function UserDelCart()
    {
        $cartModel = new CartModel();
        $cartids = input('post.cart_ids');
//        var_dump($cartids);die;
        $rs = $cartModel->delcart($this->_userid,$cartids);
        if(!$rs){
            $this->result('',-1,$cartModel->getError());
        }
        $this->result('',1,'删除成功');
    }
}
